﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace TCM.Controllers
{
    public class StudentCourseController : Controller
    {
        private TCMContext db = new TCMContext();

        //
        // GET: /StudentCourse/

        public ActionResult Index()
        {
            var studentcourses = db.STUDENTCOURSEBASEs
                .Include(s => s.COURSEBASE)
                .Include(s => s.MAPSTRINGBASE)
.Include(s => s.STUDENTBASE).Include(s => s.USERBASE);
            return View(studentcourses.ToList());
        }

        //
        // GET: /StudentCourse/Details/5

        public ActionResult Details(Guid? id = null)
        {
           var  studentcourse = db.STUDENTCOURSEBASEs.Find(id);
            if (studentcourse == null)
            {
                return HttpNotFound();
            }
            return View(studentcourse);
        }

        //
        // GET: /StudentCourse/Create

        public ActionResult Create()
        {
            ViewBag.COURSEID = new SelectList(db.COURSEBASEs, "COURSEID", "NAME");
           // ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE");
            ViewBag.STUDENTID = new SelectList(db.STUDENTBASEs, "STUDENTID", "NAME");
            ViewBag.OWNERID = new SelectList(db.USERBASEs, "USERID", "NAME");
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs
               .Where<MAPSTRINGBASE>
               (x => x.ATTRIBUTENAME.Equals("statusid") &&
                   x.ENTITYNAME.Equals("SUBJECTBASE")).ToList().AsEnumerable(), "MAPSTRINGID", "DISPLAYNAME");
            return View();
        }

        //
        // POST: /StudentCourse/Create

        [HttpPost]
        public ActionResult Create(STUDENTCOURSEBASE studentcourse)
        {
            if (ModelState.IsValid)
            {
                studentcourse.STUDENTCOURSEID= Guid.NewGuid();
                db.STUDENTCOURSEBASEs.Add(studentcourse);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.COURSEID = new SelectList(db.COURSEBASEs, "COURSEID", "NAME", studentcourse.COURSEID);
           // ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE", studentcourse.STATUSID);
            ViewBag.STUDENTID = new SelectList(db.STUDENTBASEs, "STUDENTID", "NAME", studentcourse.STUDENTID);
            ViewBag.OWNERID = new SelectList(db.USERBASEs, "USERID", "NAME", studentcourse.OWNERID);

            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs
              .Where<MAPSTRINGBASE>
              (x => x.ATTRIBUTENAME.Equals("statusid") &&
                  x.ENTITYNAME.Equals("SUBJECTBASE")).ToList().AsEnumerable(), "MAPSTRINGID", "DISPLAYNAME");

            return View(studentcourse);
        }

        //
        // GET: /StudentCourse/Edit/5

        public ActionResult Edit(Guid? id = null)
        {
            var studentcourse = db.STUDENTCOURSEBASEs.Find(id);
            if (studentcourse == null)
            {
                return HttpNotFound();
            }
            ViewBag.COURSEID = new SelectList(db.COURSEBASEs, "COURSEID", "NAME", studentcourse.COURSEID);
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE", studentcourse.STATUSID);
            ViewBag.STUDENTID = new SelectList(db.STUDENTBASEs, "STUDENTID", "NAME", studentcourse.STUDENTID);
            ViewBag.OWNERID = new SelectList(db.USERBASEs, "USERID", "NAME", studentcourse.OWNERID);
            return View(studentcourse);
        }

        //
        // POST: /StudentCourse/Edit/5

        [HttpPost]
        public ActionResult Edit(STUDENTCOURSEBASE studentcourse)
        {
            if (ModelState.IsValid)
            {
                db.Entry(studentcourse).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.COURSEID = new SelectList(db.COURSEBASEs, "COURSEID", "NAME", studentcourse.COURSEID);
            ViewBag.STATUSID = new SelectList(db.MAPSTRINGBASEs, "MAPSTRINGID", "DISPLAYVALUE", studentcourse.STATUSID);
            ViewBag.STUDENTID = new SelectList(db.STUDENTBASEs, "STUDENTID", "NAME", studentcourse.STUDENTID);
            ViewBag.OWNERID = new SelectList(db.USERBASEs, "USERID", "NAME", studentcourse.OWNERID);
            return View(studentcourse);
        }

        //
        // GET: /StudentCourse/Delete/5

        public ActionResult Delete(Guid? id = null)
        {
          var studentcourse = db.STUDENTCOURSEBASEs.Find(id);
            if (studentcourse == null)
            {
                return HttpNotFound();
            }
            return View(studentcourse);
        }

        //
        // POST: /StudentCourse/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(Guid id)
        {
          var studentcourse = db.STUDENTCOURSEBASEs.Find(id);
            db.STUDENTCOURSEBASEs.Remove(studentcourse);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}